# 868 简单：二进制间距

def binaryGap(n: int) -> int:
    start = -1
    maxm = 0
    i = 0

    while n:
        if n & 1:
            if start > -1:
                maxm = max(maxm, i - start)
                # print(maxm)
            start = i

        n >>= 1
        # print('n', n)
        i += 1

    return maxm


print(binaryGap(22))
